<template>
   <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
         <el-form-item label="识别类型" prop="recognitionType">
            <el-select v-model="queryParams.recognitionType" placeholder="识别类型" clearable style="width: 200px">
               <el-option label="人脸识别" value="face" />
               <el-option label="车牌识别" value="plate" />
               <el-option label="其他" value="other" />
            </el-select>
         </el-form-item>
         <el-form-item label="设备编号" prop="deviceCode">
            <el-input
               v-model="queryParams.deviceCode"
               placeholder="请输入设备编号"
               clearable
               style="width: 200px"
               @keyup.enter="handleQuery"
            />
         </el-form-item>
         <el-form-item label="日期范围" prop="dateRange">
            <el-date-picker
               v-model="dateRange"
               type="datetimerange"
               range-separator="至"
               start-placeholder="开始日期"
               end-placeholder="结束日期"
               style="width: 240px"
            />
         </el-form-item>
         <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
         </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
         <el-col :span="1.5">
            <el-button
               type="warning"
               plain
               icon="Download"
               @click="handleExport"
               v-hasPermi="['data:recognition:export']"
            >导出</el-button>
         </el-col>
         <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="recognitionList">
         <el-table-column type="index" label="序号" width="60" align="center" />
         <el-table-column label="识别类型" align="center" prop="recognitionType" :show-overflow-tooltip="true">
            <template #default="scope">
               <el-tag v-if="scope.row.recognitionType === 'face'">人脸识别</el-tag>
               <el-tag v-else-if="scope.row.recognitionType === 'plate'" type="success">车牌识别</el-tag>
               <el-tag v-else type="info">{{ scope.row.recognitionType }}</el-tag>
            </template>
         </el-table-column>
         <el-table-column label="设备编号" align="center" prop="deviceCode" :show-overflow-tooltip="true" />
         <el-table-column label="识别结果" align="center" prop="result" :show-overflow-tooltip="true" />
         <el-table-column label="识别时间" align="center" prop="recognitionTime" width="180">
            <template #default="scope">
               <span>{{ parseTime(scope.row.recognitionTime) }}</span>
            </template>
         </el-table-column>
         <el-table-column label="处理状态" align="center" prop="processStatus">
            <template #default="scope">
               <el-tag :type="scope.row.processStatus === 'success' ? 'success' : 'warning'">
                  {{ scope.row.processStatus === 'success' ? '已处理' : '待处理' }}
               </el-tag>
            </template>
         </el-table-column>
      </el-table>

      <pagination
         v-show="total > 0"
         :total="total"
         v-model:page="queryParams.pageNum"
         v-model:limit="queryParams.pageSize"
         @pagination="getList"
      />
   </div>
</template>

<script setup name="Recognition">
import { listRecognition } from "@/api/data/recognition";

const { proxy } = getCurrentInstance();

const recognitionList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const dateRange = ref([]);

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  recognitionType: undefined,
  deviceCode: undefined
});

/** 查询识别记录列表 */
function getList() {
  loading.value = true;
  // TODO: 调用实际API
  // listRecognition(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
  //   recognitionList.value = response.rows;
  //   total.value = response.total;
  //   loading.value = false;
  // });
  
  setTimeout(() => {
    recognitionList.value = [];
    total.value = 0;
    loading.value = false;
    proxy.$modal.msgWarning("识别记录功能开发中，请等待后端接口...");
  }, 500);
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download("data/recognition/export", {
    ...queryParams.value
  }, `recognition_${new Date().getTime()}.xlsx`);
}

getList();
</script>

